home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / pwd / c / getpwnam < prev    next >
Text File  |  1996-11-09  |  1KB  |  44 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/pwd/c/RCS/getpwnam,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: getpwnam,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: getpwnam,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* pwd.c.getpwnam. Search for an entry with a matching username.
  18.  
  19.    This is a POSIX.1 function written by Nick Burrett, 13 October 1996.  */
  20.  
  21. #include <stddef.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <pwd.h>
  25.  
  26. /* Search for an entry with a matching name.  */
  27. struct passwd *
  28. getpwnam (const char *name)
  29. {
  30.   FILE *stream;
  31.   struct passwd *p;
  32.  
  33.   stream = fopen ("/etc/passwd", "r");
  34.   if (stream == NULL)
  35.     return NULL;
  36.  
  37.   while ((p = fgetpwent (stream)) != NULL)
  38.     if (!strcmp(p->pw_name, name))
  39.       break;
  40.  
  41.   fclose (stream);
  42.   return p;
  43. }
  44.